/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : day_reserve.js                                 
*  Description  : 조인룸 리스트                                       
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-04-12  김효순    Created.  
*  2012-04-16  김효순    Complete.(통신제외)
*******************************************************************************/

jQuery(function($){
	// 현재 진행현황
	function clsProgressStatus()
	{
		this._HTMLDom = null;
		
		this._init();
	}
	
	clsProgressStatus.prototype = {
		_init: function(){
			var $layer = $("div#container").find("section#main_content").find("dl.now_state:first>dd");
			
			this._HTMLDom = {
				"$layer":  $layer // 출력화면
				, "$dateBox": $layer.find("p:eq(0)") // 날짜
				, "$corseBox": $layer.find("p:eq(1)") // 코스
				, "$timeBox": $layer.find("p:eq(2)") // 시간
				, "$teamBox": $layer.find("p:eq(3)") // 팀
			}
			
			this._display();
		}
		, _display: function(){
			with(this._HTMLDom){
				$dateBox.empty();
				$corseBox.empty();
				$timeBox.empty();
				$teamBox.empty();
			}
		}
		, displayDate: function(szDate){
			with(this._HTMLDom){
				$dateBox.html(szDate);
				$corseBox.empty();
				$timeBox.empty();
				$teamBox.empty();
			}
		}
		, displayCourse: function(szCourse){
			with(this._HTMLDom){
				$corseBox.html(szCourse);
				$timeBox.empty();
				$teamBox.empty();
			}
		}
		, displayTime: function(szTime){
			with(this._HTMLDom){
				$timeBox.html(szTime);
				$teamBox.empty();
			}
		}
		, displayTeam: function(szTeam){
			with(this._HTMLDom){
				$teamBox.html(szTeam);
			}
		}
	}
	
	// 전체 평일 주말
	function clsReserveCho()
	{
		this._HTMLDom = null;
		
		this._init();
	}
	
	clsReserveCho.prototype = {
		_init: function(){
			var $layer = $("div#container").find("section#main_content").find("div.reserve_cho:first");
			
			this._HTMLDom = {
				"$layer": $layer
				, "$radio": $layer.find("input:radio")
			}
			
			this._HTMLDom["$radio"].eq(0).attr("checked", true);
		}
		, $getsRadio:function(){
			return this._HTMLDom["$radio"];
		}
	}
	
	// 달력
	function clsCalendar()
	{
		this._HTMLDom = null;
		this._enableType = null;
		
		this._init();
	}
	
	clsCalendar.prototype = {
		_init: function(){
			var $layer = $("div#container").find("section#main_content").find("dl.reserve_calendar:first");
			
			this._HTMLDom = {
				"$layer": $layer
				, "$calendarBox": $layer.find("tr") // 루프박스
				, "$dayElement": $layer.find("td:first").clone(true) // 날짜 엘리먼트
				, "$leftMonth": $layer.find("p.c_bt_p") // 월 이동버튼
				, "$rightMonth": $layer.find("p.c_bt_n") // 월 이동버튼
				, "$leftDay": $layer.find("p.td_prev") // 일 이동버튼
				, "$rightDay": $layer.find("p.td_next") // 일 이동버튼
			}
			
			this._enableType = null;
			
			this.setUp();
			this.display();
		}
		, setUp: function(){
			var newDate = new Date();
			newDate.setDate(1);
			
			// 달력레이어에 현재 년월 저장
			this._HTMLDom["$layer"].data({
				"dispDate": newDate // 화면상의 날짜
				, "selDate": null // 선택된 날짜
			});
		}
		, display: function(){
			var _weekday = ["일", "월", "화", "수", "목", "금", "토"];
			var dispDate = this._HTMLDom["$layer"].data("dispDate");
			var startDate = new Date(dispDate.getFullYear(), dispDate.getMonth(), dispDate.getDate());
			var $calendarBox = this._HTMLDom["$calendarBox"];
			
			this._HTMLDom["$layer"].find("dt:first>p:eq(1)").html(dispDate.getFullYear() + "." + (dispDate.getMonth()+1))
			
			$calendarBox.empty();
			
			for(var i=0;i<18;i++){
				var szWeekClass = "";
				if(startDate.getDay() == 6) szWeekClass = "saturday";
				else if(startDate.getDay() == 0) szWeekClass = "holiday";
					
				$calendarBox.append(this._HTMLDom["$dayElement"].clone(true)).find("td:last").data({"year": startDate.getFullYear(), "month": startDate.getMonth(), "day": startDate.getDate()}).addClass(szWeekClass).find("span:eq(0)").html(_weekday[startDate.getDay()]).next().html(startDate.getDate());
				
				startDate.setDate(startDate.getDate()+1);
			}
			
			switch(this._enableType){
				case 1 :
					$calendarBox.find("td.saturday, td.holiday").addClass("non_active");
					break;
				case 2 :
					$calendarBox.find("td").addClass("non_active").filter(".saturday, .holiday").removeClass("non_active");
					break;
			}
			
			this.displayRed();
			
			this.bind();
		}
		, bind: function(){
			var thisClass = this;
			
			// 일자선택
			this._HTMLDom["$calendarBox"].find("td").click(function(event){
				event.preventDefault();
				
				if($(this).hasClass("non_active")) return;
				
				thisClass._HTMLDom["$layer"].data("selDate", new Date($(this).data("year"), $(this).data("month"), $(this).data("day")));
				
				thisClass.displayRed();
				
				// 진행사항 표시를 위해 이벤트 발생
				$(thisClass).trigger("evtDayClick");
			});
		}
		, displayRed: function(){
			var thisClass = this;
			
			if(!this._HTMLDom["$layer"].data("selDate")) return;
			
			this._HTMLDom["$calendarBox"].find("td").each(function(){
				var selDate = thisClass._HTMLDom["$layer"].data("selDate");
				
				if($(this).data("year") == selDate.getFullYear() && $(this).data("month") == selDate.getMonth() && $(this).data("day") == selDate.getDate()) $(this).addClass("d_over");
				else $(this).removeClass("d_over");
			});
		}
		// 선택된 날짜 반환
		, getDate: function(){
			var selDate = this._HTMLDom["$layer"].data("selDate");
			
			if(selDate == null) return "";
			
			var szYear = selDate.getFullYear()+"";
			var szMonth = (selDate.getMonth()+1)+"";
			var szDay = selDate.getDate()+"";
			
			if(szMonth.length < 2) szMonth = "0" + szMonth;
			if(szDay.length < 2) szDay = "0" + szDay;
			
			return szYear + ". " + szMonth + ". " + szDay;
		}
		, setEnableType: function(val){
			this._enableType = val;
			
			this.display();
		}
		// 일자 선택 박스
		, $getDateBind: function(){
			return this._HTMLDom["$calendarBox"].find("td");
		}
		// display date 객체
		, getObjDispDate: function(){
			return this._HTMLDom["$layer"].data("dispDate");
		}
		// 왼쪽 월이동 버튼
		, $getBtnLeftMonth: function(){
			return this._HTMLDom["$leftMonth"];
		}
		// 오른쪽 월이동 버튼
		, $getBtnRightMonth: function(){
			return this._HTMLDom["$rightMonth"];
		}
		// 왼쪽 일이동 버튼
		, $getBtnLeftDay: function(){
			return this._HTMLDom["$leftDay"];
		}
		// 오른쪽 일이동 버튼
		, $getBtnRightDay: function(){
			return this._HTMLDom["$rightDay"];
		}
	}
	
	// 코스장
	function clsCourse()
	{
		this._HTMLDom = null;
		this.reqData = null;
		this.resData = null;
		
		this._init();
	}
	
	clsCourse.prototype = {
		_init: function(){
			var $layer = $("div#container").find("section#main_content");
			this._HTMLDom = {
				"$layer": $layer.find("ul.reserve_course:first")
				, "$infoLayer": $layer.find("dl.reserve_course_info")
				, "$listElement": $layer.find("ul.reserve_course:first").find("li:first").clone(true)
			}
			
			this.reqData = {
				"szDate": ""
			}
			
			this.setUp();

		}
		, setUp: function(){
			this._HTMLDom["$layer"].data("idx", null); // 인덱스 저장
			
			this._HTMLDom["$layer"].hide();
			this._HTMLDom["$infoLayer"].hide();
			
			this.resData = [
				
			];
		}
		, getList: function(){
			this.setUp();
			
			// ajax
			
			this.resData = [
				{
					"key": "001"
					, "szField": "골프장명01"
					, "szCourse": "오션코스명01"
				}
				, {
					"key": "002"
					, "szField": "골프장명02"
					, "szCourse": "오션코스명02"
				}
				, {
					"key": "003"
					, "szField": "골프장명03"
					, "szCourse": "오션코스명03"
				}
				, {
					"key": "004"
					, "szField": "골프장명04"
					, "szCourse": "오션코스명04"
				}
				, {
					"key": "005"
					, "szField": "골프장명05"
					, "szCourse": "오션코스명05"
				}
			];
			
			this.display();
		}
		, display: function(){
			var thisClass = this;
			
			var $layer = this._HTMLDom["$layer"];
			var $element = this._HTMLDom["$listElement"];
			
			$layer.show();
			this._HTMLDom["$infoLayer"].show();
			
			$layer.empty();
			for(var i=0;i<this.resData.length;i++){
				$layer.append($element.clone(true)).find("li:last").data(this.resData[i]);
			}
			
			$layer.find("li").each(function(){
				$(this).find("span.course_name").text($(this).data("szField")).next("span").text($(this).data("szCourse"));
				
				$(this).click(function(event){
					event.preventDefault();
					
					var idx = $layer.find("li").index($(this));
					
					thisClass._HTMLDom["$layer"].data("idx", idx);
					thisClass.displayRed();
					
					$(thisClass).trigger("evtCourseSelect");
				});
			});
		}
		, displayRed: function(){
			var $layer = this._HTMLDom["$layer"];
			 var idx = $layer.data("idx");
			 
			 if(idx == null) return;
			 
			 $layer.find("li").removeClass("c_over").eq(idx).addClass("c_over");
		}
		, setReqData: function(key, val){
			this.reqData[key] = val;
		}
		, getString: function(){
			 var $layer = this._HTMLDom["$layer"];
			 var idx = $layer.data("idx");
			 
			 if(idx == null) return "";
			 
			 return this.resData[idx]["szField"] + " " + this.resData[idx]["szCourse"];
		}
		, getKey: function(){
			var $layer = this._HTMLDom["$layer"];
			 var idx = $layer.data("idx");
			 
			 if(idx == null) return null;
			
			return this.resData[idx]["key"];
		}
	}
	
	
	// 시간
	function clsBookingTime()
	{
		this._HTMLDom = null;
		this.reqData = null;
		this.resData = null;
		
		this._init();
	}
	
	clsBookingTime.prototype = {
		_init: function(){
			var $with = $("div#container").find("section#main_content");
			
			with($with){
				this._HTMLDom = {
					"$layer": find("div.reserve_time_list:first")
					, "$timeBox": find("div.reserve_time") // 시간바
					, "$noMsg": find("p.reserve_no_mess01")
					, "$leftBox": find("div.ta_float:eq(0)>table>tbody")
					, "$middleBox": find("div.ta_float:eq(1)>table>tbody")
					, "$rightBox": find("div.ta_float:eq(2)>table>tbody")
					, "$listElement": find("div.ta_float:eq(0)>table>tbody>tr:first").clone(true)
				}
			}
			
			this.reqData = {
				"szDate": ""
				, "iCourse": null
				, "iTime": 12
			}

			this.setUp();
		}
		, setUp: function(){
			this._HTMLDom["$layer"].data({
				"idx": null
				, "$pos": null
			}); // 시간 키 저장공간
			
			this.resData = {
				"left": [
				
				]
				, "middle": [
				
				]
				, "right": [
				
				]
			}
			
			this._HTMLDom["$layer"].hide();
			this._HTMLDom["$timeBox"].hide();
			this._HTMLDom["$noMsg"].show();
		}
		, setReqData: function(key, val){
			this.reqData[key] = val;
		}
		, getList: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"], $timeBox = this._HTMLDom["$timeBox"], $noMsg = this._HTMLDom["$noMsg"];
			
			this.setUp();
			$layer.show(); $timeBox.show(); $noMsg.hide();
			
			this.getLeftList();
			this.getMiddleList();
			this.getRightList();
			this.displaySetTime();
			this.displayRed();
			
			// 선택이벤트
			this._HTMLDom["$layer"].find("tr").click(function(event){
				event.preventDefault();
				
				var pos = $(this).data("pos");
				var $thisBox = thisClass._HTMLDom["$" + pos + "Box"];
				var idx = $thisBox.find("tr").index($(this));
				
				thisClass._HTMLDom["$layer"].data({
					"idx": idx
					, "pos": pos
				});
				
				thisClass.displayRed();
				
				$(thisClass).trigger("evtSelect");
			});
		}
		, getLeftList: function(){
			var $leftBox = this._HTMLDom["$leftBox"];
			
			//this.reqData["iTime"] -= 1;
			
			$leftBox.empty();
			
			// ajax
			
			this.resData["left"] = [
				{
					"key": "001"
					, "szTime": "11:00"
					, "inout": "in"
					, "szCourse": "하늘코스"
					, "event": {
						"szTitle": "[ 이벤트 ]"
						, "szNote": "식사할인 50% <br/>카트할일 70%"
					}
					, "szPrice": "210,000"
				}
				, {
					"key": "002"
					, "szTime": "11:01"
					, "inout": "out"
					, "szCourse": "하늘코스1"
					, "event": {
						"szTitle": "[ 이벤트 ]"
						, "szNote": "식사할인 50% <br/>카트할일 70%"
					}
					, "szPrice": "215,000"
				}
			];
			
			this.leftDisplay();
		}
		, getMiddleList: function(){
			var $middleBox = this._HTMLDom["$middleBox"];
			
			$middleBox.empty();
			
			// ajax
			
			this.resData["middle"] = [
				{
					"key": "003"
					, "szTime": "12:00"
					, "inout": "in"
					, "szCourse": "하늘코스3"
					, "event": {
						"szTitle": "[ 이벤트 ]"
						, "szNote": "식사할인 50% <br/>카트할일 70%"
					}
					, "szPrice": "230,000"
				}
				, {
					"key": "004"
					, "szTime": "12:01"
					, "inout": "out"
					, "szCourse": "하늘코스4"
					, "event": null
					, "szPrice": "245,000"
				}
			];
			
			this.middleDisplay();
		}
		, getRightList: function(){
			var $rightBox = this._HTMLDom["$rightBox"];
			
			$rightBox.empty();
			
			// ajax
			
			this.resData["right"] = [
				{
					"key": "005"
					, "szTime": "13:00"
					, "inout": "in"
					, "szCourse": "하늘코스5"
					, "event": {
						"szTitle": "[ 이벤트 ]"
						, "szNote": "식사할인 50% <br/>카트할일 70%"
					}
					, "szPrice": "290,000"
				}
				, {
					"key": "006"
					, "szTime": "13:01"
					, "inout": "out"
					, "szCourse": "하늘코스6"
					, "event": null
					, "szPrice": "225,000"
				}
			];
			
			this.rightDisplay();
		}
		, leftDisplay: function(){
			var $leftBox = this._HTMLDom["$leftBox"];
			var $element = this._HTMLDom["$listElement"];
			var thisClass = this;
			
			for(var i=0;i<this.resData["left"].length;i++){
				// tr엘리먼트에 데이터 저장. 위치엘리먼트 저장.
				$leftBox.append($element.clone(true)).find("tr:last").data(this.resData["left"][i]).data("pos", "left");
			}
			
			$leftBox.find("tr").each(function(){
				var aImgPath = $(this).find("span.ico>img").attr("src").replace("_in.gif", "");
				
				$(this).find("th:first").html($(this).data("szTime")); // 시간
				$(this).find("span.ico>img").attr("src", aImgPath + "_" + $(this).data("inout") + ".gif"); // inout
				$(this).find("td").contents().filter(function(){
					return (this.nodeType == 3 && this.nodeValue == "하늘코스");
				}).parent("td").html($(this).data("szCourse")); // 코스
				$(this).find("td.td_r").html("\\" + $(this).data("szPrice")); // 가격
				
				if($(this).data("event")){
					// 이벤트 내용 show
					$(this).find("div.div_pos").hover(function(){
						if($.browser["msie"] && $.browser["version"] < 8){
							if(event.type == "mouseenter" || event.type == "mouseover"){
								thisClass._HTMLDom["$timeBox"].addClass("z_pos");
								$leftBox.find("div.div_pos").not($(this)).addClass("z_pos");
							}else if(event.type == "mouseleave" || event.type == "mouseout"){
								thisClass._HTMLDom["$timeBox"].removeClass("z_pos");
								$leftBox.find("div.div_pos").not($(this)).removeClass("z_pos");
							}
						}
						
						$(this).find("div.event_layer").toggle();
					});
				}else{
					$(this).find("div.div_pos").empty();
				}
			});
		}
		, middleDisplay: function(){
			var $middleBox = this._HTMLDom["$middleBox"];
			var $element = this._HTMLDom["$listElement"];
			var thisClass = this;
			
			for(var i=0;i<this.resData["middle"].length;i++){
				$middleBox.append($element.clone(true)).find("tr:last").data(this.resData["middle"][i]).data("pos", "middle");
			}
			
			$middleBox.find("tr").each(function(){
				var aImgPath = $(this).find("span.ico>img").attr("src").replace("_in.gif", "");
				
				$(this).find("th:first").html($(this).data("szTime"));
				$(this).find("span.ico>img").attr("src", aImgPath + "_" + $(this).data("inout") + ".gif");
				$(this).find("td").contents().filter(function(){
					return (this.nodeType == 3 && this.nodeValue == "하늘코스");
				}).parent("td").html($(this).data("szCourse"));
				$(this).find("td.td_r").html("\\" + $(this).data("szPrice"));
				
				if($(this).data("event")){
					// 이벤트 내용 show
					$(this).find("div.div_pos").hover(function(){
						if($.browser["msie"] && $.browser["version"] < 8){
							if(event.type == "mouseenter" || event.type == "mouseover"){
								thisClass._HTMLDom["$timeBox"].addClass("z_pos");
								$middleBox.find("div.div_pos").not($(this)).addClass("z_pos");
							}else if(event.type == "mouseleave" || event.type == "mouseout"){
								thisClass._HTMLDom["$timeBox"].removeClass("z_pos");
								$middleBox.find("div.div_pos").not($(this)).removeClass("z_pos");
							}
						}
						
						$(this).find("div.event_layer").toggle();
					});
				}else{
					$(this).find("div.div_pos").empty();
				}
			});
		}
		, rightDisplay: function(){
			var $rightBox = this._HTMLDom["$rightBox"];
			var $element = this._HTMLDom["$listElement"];
			var thisClass = this;
			
			for(var i=0;i<this.resData["right"].length;i++){
				$rightBox.append($element.clone(true)).find("tr:last").data(this.resData["right"][i]).data("pos", "right");
			}
			
			$rightBox.find("tr").each(function(){
				var aImgPath = $(this).find("span.ico>img").attr("src").replace("_in.gif", "");
				
				$(this).find("th:first").html($(this).data("szTime"));
				$(this).find("span.ico>img").attr("src", aImgPath + "_" + $(this).data("inout") + ".gif");
				$(this).find("td").contents().filter(function(){
					return (this.nodeType == 3 && this.nodeValue == "하늘코스");
				}).parent("td").html($(this).data("szCourse"));
				$(this).find("td.td_r").html("\\" + $(this).data("szPrice"));
				
				if($(this).data("event")){
					// 이벤트 내용 show
					$(this).find("div.div_pos").hover(function(){
						if($.browser["msie"] && $.browser["version"] < 8){
							if(event.type == "mouseenter" || event.type == "mouseover"){
								thisClass._HTMLDom["$timeBox"].addClass("z_pos");
								$rightBox.find("div.div_pos").not($(this)).addClass("z_pos");
							}else if(event.type == "mouseleave" || event.type == "mouseout"){
								thisClass._HTMLDom["$timeBox"].removeClass("z_pos");
								$rightBox.find("div.div_pos").not($(this)).removeClass("z_pos");
							}
						}
						
						$(this).find("div.event_layer").toggle();
					});
				}else{
					$(this).find("div.div_pos").empty();
				}
			});
		}
		, displaySetTime:function(){
			var curTime = this.reqData["iTime"];
			var curPos = (curTime-5)*41;
			var $layer = this._HTMLDom["$timeBox"].find("tbody tr");
			var $red = this._HTMLDom["$timeBox"].find("p.t_over");
			
			$red.animate({left: curPos});
		}
		, displayRed: function(){
			var $layer = this._HTMLDom["$layer"];
			var $red = $layer.find("p.t_over:first");
			var pos = $layer.data("pos");
			var idx = $layer.data("idx");
			var $leftBox = this._HTMLDom["$leftBox"], $middleBox = this._HTMLDom["$middleBox"], $rightBox = this._HTMLDom["$rightBox"];
			var targetTopPos = idx*32;
			var aTargetLeftPos = {
				"left": 0
				, "middle": 231
				, "right": 463
			};
			
			if(pos == null || idx == null){
				$red.hide();
				return;
			}
			
			$red.show();
			$red.animate({"top":targetTopPos + "px", "left": aTargetLeftPos[pos] + "px"});
		}
		, $getsBtnTimeBar: function(){
			return this._HTMLDom["$timeBox"].find("tbody tr td");
		}
		, $getTimeBarRed: function(){
			return this._HTMLDom["$timeBox"].find("p.t_over");
		}
		, setLeftTimeBar: function(){
			if(this.reqData["iTime"] == 5) return;
			this.reqData["iTime"]--;
			
			this.getList();
		}
		, setRightTimeBar: function(){
			if(this.reqData["iTime"] == 19) return;
			this.reqData["iTime"]++;
			
			this.getList();
		}
		, getTimeString: function(){
			var $layer = this._HTMLDom["$layer"];
			var pos = $layer.data("pos");
			var idx = $layer.data("idx");
			
			return this.resData[pos][idx]["szTime"];
		}
		, getKey: function(){
			var $layer = this._HTMLDom["$layer"];
			var pos = $layer.data("pos");
			var idx = $layer.data("idx");
			
			if(pos == null || idx == null) return null;
			
			return this.resData[pos][idx]["key"];
		}
	}
	
	function clsTeam()
	{
		this._HTMLDom = null;
		this.reqData = null;
		this.resData = null;
		
		this._init();
	}
	
	clsTeam.prototype = {
		_init: function(){
			var $layer = $("div#container").find("section#main_content").find("ul.reserve_team");
			
			this._HTMLDom = {
				"$layer": $layer
				, "$noMsg": $("div#container").find("section#main_content").find("p.reserve_no_mess02")
				, "$listElement": $layer.find("li:first").clone(true)
			}
			
			this.reqData = {
				"szDate": ""
				, "iCourse": null
				, "iTime": null
			}
			
			this.setUp();
		}
		, setUp: function(){
			var $layer = this._HTMLDom["$layer"], $noMsg = this._HTMLDom["$noMsg"];
			
			$layer.data("idx", null); // 팀 인덱스 저장 공간
			
			this.resData = [
			
			];
			
			$layer.hide();
			$noMsg.show();
		}
		, setReqData: function(key, val){
			this.reqData[key] = val;
		}
		, getList: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"], $noMsg = this._HTMLDom["$noMsg"];
			
			this.setUp();
			$layer.show(); $noMsg.hide();
			
			$layer.empty();
			$layer.spin();
			// ajax
			
			this.resData = [
				"2", "3", "4"
			];
			$layer.spin(false);
			
			this.display();
			
			// 선택이벤트
			$layer.find("li").click(function(event){
				event.preventDefault();
				
				var idx = $layer.find("li").index($(this));
				$layer.data("idx", idx);
				
				thisClass.displayRed();
				
				$(thisClass).trigger("evtSelect");
			});
		}
		, display: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"];
			var $listElement = this._HTMLDom["$listElement"];
			
			$layer.empty();
			for(var i=0;i<this.resData.length;i++){
				$layer.append($listElement.clone(true)).find("li:last").html(this.resData[i] + "인 1팀");
			}
		}
		, displayRed: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"];
			var idx = $layer.data("idx");
			
			$layer.find("li").removeClass("t_over").eq(idx).addClass("t_over");
		}
		, getTeamString: function(){
			var thisClass = this;
			var $layer = this._HTMLDom["$layer"];
			var idx = $layer.data("idx");
			
			return $layer.find("li:eq(" + idx + ")").text();
		}
	}
	
	function clsSubmit()
	{
		this._HTMLDom = null;
		this.reqData = null;
		this.resData = null;
		this.objError = null;
		
		this._init();
	}
	
	clsSubmit.prototype = {
		_init: function(){
			var $layer = $("section#main_content p.btn_center:last");
			
			this._HTMLDom = {
				"$layer": $layer
				, "$btnSubmit": $layer.find("a")
			}
			
			this.reqData = {
				"szDate": ""
				, "iCourse": null
				, "iTime": null
				, "szTeam": ""
			}
			
			this.resData = {
				"msg": null
			}
			
			this.objError = {
				"szError": ""
			}
		}
		, submit: function(){
			var $layer = this._HTMLDom["$layer"], $btnSubmit = this._HTMLDom["$btnSubmit"];
			
			this.szError = "";
			
			if(!this.reqData["szDate"]){
				this.objError["szError"] = "날짜를 선택해 주십시요.";
				return false;
			}else if(this.reqData["iCourse"] == null){
				this.objError["szError"] = "코스를 선택해 주십시요.";
				return false;
			}else if(this.reqData["iTime"] == null){
				this.objError["szError"] = "시간을 선택해 주십시요.";
				return false;
			}else if(!this.reqData["szTeam"]){
				this.objError["szError"] = "인원을 선택해 주십시요.";
				return false;
			}
			
			$btnSubmit.hide();
			$layer.spin();
			
			// ajax
			
			return true;
		}
		, setReqData: function(obj){
			this.reqData = obj;
		}
		, getErrorMsg: function(){
			return this.objError["szError"];
		}
		, $getBtnSubmit: function(){
			return this._HTMLDom["$btnSubmit"];
		}
	}

	
	
	function clsControl()
	{
		this.objProgressStatus = null;
		this.objReserveCho = null;
		this.objCalendar = null;
		this.objCourse = null;
		this.objBookingTime = null;
		this.objTeam = null;
		this.objSubmit = null;
		
		this._init();
	}
	
	clsControl.prototype = {
		_init: function(){
			this.objProgressStatus = new clsProgressStatus();
			this.objReserveCho = new clsReserveCho();
			this.objCalendar = new clsCalendar();
			this.objCourse = new clsCourse();
			this.objBookingTime = new clsBookingTime();
			this.objTeam = new clsTeam();
			this.objSubmit = new clsSubmit();
			
			this._bind();
		}
		, _bind: function(){
			var thisClass = this;
			
			// 전체 평일 주말
			this.objReserveCho.$getsRadio().click(function(event){
				var idx = thisClass.objReserveCho.$getsRadio().index($(this));
				
				thisClass.objCalendar.setUp();
				thisClass.objCourse.setUp();
				thisClass.objBookingTime.setUp();
				thisClass.objTeam.setUp();
				
				thisClass.objCalendar.setEnableType(idx);
				
				thisClass.objProgressStatus._display();
			});
			
			// 월 이동(왼쪽)
			this.objCalendar.$getBtnLeftMonth().click(function(event){
				event.preventDefault();
				
				thisClass.objCalendar.getObjDispDate().setDate(1);
				thisClass.objCalendar.getObjDispDate().setMonth(thisClass.objCalendar.getObjDispDate().getMonth()-1);

				thisClass.objCalendar.display();
			});
			
			// 월 이동(오른쪽)
			this.objCalendar.$getBtnRightMonth().click(function(event){
				event.preventDefault();
				
				thisClass.objCalendar.getObjDispDate().setDate(1);
				thisClass.objCalendar.getObjDispDate().setMonth(thisClass.objCalendar.getObjDispDate().getMonth()+1);

				thisClass.objCalendar.display();
			});
			
			// 일 이동(왼쪽)
			this.objCalendar.$getBtnLeftDay().click(function(event){
				event.preventDefault();
				
				thisClass.objCalendar.getObjDispDate().setDate(thisClass.objCalendar.getObjDispDate().getDate()-1);
				
				thisClass.objCalendar.display();
			});
			
			// 일 이동(오른쪽)
			this.objCalendar.$getBtnRightDay().click(function(event){
				event.preventDefault();
				
				thisClass.objCalendar.getObjDispDate().setDate(thisClass.objCalendar.getObjDispDate().getDate()+1);
				
				thisClass.objCalendar.display();
			});
			
			// 일자 선택시 발생시킬 이벤트 핸들링
			$(this.objCalendar).bind("evtDayClick", {"parentClass": this}, function(event){
				var thisClass = event.data["parentClass"];
				
				thisClass.objProgressStatus.displayDate(this.getDate());
				
				thisClass.objCourse.setReqData("szDate", this.getDate());
				thisClass.objCourse.getList();
				
				thisClass.objBookingTime.setUp();
				thisClass.objTeam.setUp();
			});
			
			//골프장 선택시 발생시킬 이벤트 핸들링
			$(this.objCourse).bind("evtCourseSelect", {"parentClass": this}, function(event){
				var thisClass = event.data["parentClass"];
				
				thisClass.objProgressStatus.displayCourse(this.getString());
				
				thisClass.objBookingTime.setReqData("szDate", thisClass.objCalendar.getDate());
				thisClass.objBookingTime.setReqData("iCourse", this.getKey());
				thisClass.objBookingTime.getList();
				
				thisClass.objTeam.setUp();
			});
			
			// 시간바 선택
			this.objBookingTime.$getsBtnTimeBar().not(":first, :last").click(function(event){
				event.preventDefault();
				var setTime = $(this).parent("tr").find("td").index($(this))+4;
				
				thisClass.objProgressStatus.displayCourse(thisClass.objCourse.getString());
				thisClass.objBookingTime.setReqData("iTime", setTime);
				thisClass.objBookingTime.getList();
				
				thisClass.objTeam.setUp();
			});
			
			// over된 시간바 선택
			this.objBookingTime.$getTimeBarRed().click(function(event){
				event.preventDefault();
				var offX = event.offsetX, offY = event.offsetY;
				
				if(Math.floor(offX/41) < 1){
					thisClass.objBookingTime.setLeftTimeBar();
				}else if(Math.floor(offX/41) >= 2){
					thisClass.objBookingTime.setRightTimeBar();
				}else{
					return;
				}
				
				thisClass.objProgressStatus.displayCourse(thisClass.objCourse.getString());
				thisClass.objTeam.setUp();
			});
			
			// 코스시간 선택
			$(this.objBookingTime).bind("evtSelect", {"parentClass": this}, function(event){
				var thisClass = event.data["parentClass"];
				
				thisClass.objProgressStatus.displayTime(this.getTimeString());
				thisClass.objTeam.setReqData("szDate", thisClass.objCalendar.getDate());
				thisClass.objTeam.setReqData("iCourse", thisClass.objCourse.getKey());
				thisClass.objTeam.setReqData("iTime", this.getKey());
				thisClass.objTeam.getList();
			});
			
			// 팀 선택
			$(this.objTeam).bind("evtSelect", {"parentClass": this}, function(event){
				var thisClass = event.data["parentClass"];
				
				thisClass.objProgressStatus.displayTeam(this.getTeamString());
			});
			
			// 예약하기
			this.objSubmit.$getBtnSubmit().click(function(event){
				event.preventDefault();
				
				thisClass.objSubmit.setReqData({
					"szDate": thisClass.objCalendar.getDate()
					, "iCourse": thisClass.objCourse.getKey()
					, "iTime": thisClass.objBookingTime.getKey()
					, "szTeam": thisClass.objTeam.getTeamString()
				});
				
				if(thisClass.objSubmit.submit()){
					
				}else{
					alert(thisClass.objSubmit.getErrorMsg());
				}
			});
		}
	}
	
	document.objControl = new clsControl();
});